package com.wv.api.server.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.wv.api.server.common.BaseController;
import com.wv.api.service.ISysMenuService;
import com.wv.common.result.Result;
import com.wv.model.system.SysMenu;
import com.wv.model.system.dto.RoleMenuDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysMenu")
@Api(tags = "菜单相关接口")
public class SysMenuController extends BaseController {

    @Autowired
    private ISysMenuService sysMenuService;

    @GetMapping("/menu")
    @ApiOperation(value = "获取用户菜单")
    public SaResult menuByUseId(){
        Object loginId = StpUtil.getLoginId();
        return sysMenuService.getByUserId(loginId.toString());
    }

    @GetMapping("/{roleId}")
    public Result menuByRoleId(@PathVariable("roleId") String roleId) {
       return sysMenuService.getMenuByRoleId(roleId);
    }

    @PutMapping("roelMenu")
    public Result RoleMenu(@RequestBody RoleMenuDto dto){
        return sysMenuService.changeRoleMenu(dto);
    }

    @GetMapping
    @SaCheckPermission("menu:list")
    @ApiOperation(value = "获取菜单列表")
    public SaResult menu() {
        return sysMenuService.getByUserId(null);
    }

    @PostMapping
    @SaCheckPermission("menu:add")
    @ApiOperation(value = "新增菜单")
    public SaResult add(@RequestBody SysMenu sysMenu) {
        return sysMenuService.save(sysMenu);
    }

    @PutMapping
    @SaCheckPermission("menu:update")
    @ApiOperation(value = "修改菜单")
    public SaResult update(@RequestBody SysMenu sysMenu) {
        return sysMenuService.update(sysMenu);
    }

    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除菜单")
    @SaCheckPermission("menu:delete")
    public SaResult delete(@PathVariable("ids") String[] ids){
        return sysMenuService.remove(ids);
    }



}
